var text = document.getElementById("text");
var paw = document.getElementById("paw");
var btn = document.getElementsByTagName("button")[0];
var user = document.getElementById("user");
var ma = document.getElementsByClassName("ma")[0];
var login = document.getElementsByClassName("logcon")[0];
var login1 = document.getElementsByClassName("log1")[0];
var zhang = document.getElementsByClassName("zhang")[0];
// btn.onclick = function () {
//     var valu = text.value;
//     var pawval = paw.value;
//     var input = /^\s+$/g;
//     var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
//     if (!valu.length < 11 || !myreg.test(valu) || input.test(valu)) {
//         user.style.display = 'block';
//     }
//     if (valu.length == 11) {
//         user.style.display = 'none';
//     };
//     if(pawval.length<6){
//         user.style.display = 'block';
//     }
//     if (pawval.length>=6) {
//         user.style.display = 'none';
//         window.location.href = 'http://localhost:8080/index.html';
//     }
// }

ma.onclick = function () {
    login1.style.display = 'block';
    login.style.display = 'none';
    this.style.color = '#ff5b00';
    zhang.style.color = '#666665'
}
zhang.onclick = function () {
    login1.style.display = 'none';
    login.style.display = 'block';
    this.style.color = '#ff5b00';
    ma.style.color = '#666665'
}

$(function () {
    $("button").on("click", function () {
        var val = $("#text").val();
        var paw = $("#paw").val();
        if(val.length>=2 && paw.length>=2){
             $.post("http://47.104.244.134:8080/userlogin.do", { "name": val, "password": paw }, function (data) {
            //成功时 存到cokie里
            if (data.code == 0) {
                var take = data.data;
                 $.cookie("token",take.token,{"expires":7,"path":"/"})
                location.href = "index.html";
            }if(data.code==1){
                $("#user").css("display","block")
            }
        });
        }
       
    })

})